﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class admin_ChangePwd : System.Web.UI.Page
{
    db_admin admin = new db_admin();
    db_teacher teacher = new db_teacher();
    protected void Page_Load(object sender, EventArgs e)
    {
        Server.Execute("inc/checkPurview.aspx");  // 此处用户权限验证
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string pwd = Tools.mymd5(yPWD.Text);
        
        if (Session["adminName"] != null)
        {
	        if (teacher.checkPwd(Session["adminName"].ToString(), pwd))
	        {
	            if (admin.setPwd(Session["adminName"].ToString(), Tools.mymd5(xPWD1.Text)))
	            {
	                Session.Clear();
	                Response.Write("<script language=javascript>alert('修改密码成功！现在请重新登录。');top.location.href='index.aspx';</script>");
	            }
	            else
	            {
	                Response.Write("<script language=javascript>alert('修改失败！');</script>");
	            }
	        }
	        else
	        {
	            Response.Write("<script language=javascript>alert('原密码错误！');</script>");
	        }
        }
        else
        {
	        if (teacher.checkPwd(Session["teacherId"].ToString(), pwd))
	        {
	            if (teacher.setPwd(Session["teacherId"].ToString(), Tools.mymd5(xPWD1.Text)))
	            {
	                Session.Clear();
	                Response.Write("<script language=javascript>alert('修改密码成功！现在请重新登录。');top.location.href='index.aspx';</script>");
	            }
	            else
	            {
	                Response.Write("<script language=javascript>alert('修改失败！');</script>");
	            }
	        }
	        else
	        {
	            Response.Write("<script language=javascript>alert('原密码错误！');</script>");
	        }
        
        }

    }
}
